<?php

require_once("config.php");

$apiClient = new KewegoClient();

//set the application token from the application key
if ($apiClient->setAppToken($application_key)) {}
else die( "<hr />Error: can not set appToken, invalid application key<hr />");

//debug: echo '<hr />appToken : '.$apiClient->returnAppToken();

/* get Top Videos */
$apiClient->Call($apiServer.'search/getTopVideos/');
//debug: echo($api->getResponse());

$xml = new SimpleXMLElement($apiClient->getResponse());
$items = $xml->message->item;
//debug: print_r($items);

/* display Videos */
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style>
img {
	border: 0px;
}

.item {
	float: left;
	width: 250px;
	height: 200px;
	margin-left: 15px;
	margin-bottom: 15px;
	padding: 3px;
	text-align: center;
	border: 3px solid transparent;
	overflow:hidden;
}

div.item:hover {
	border: 3px solid blue;
}

div.items {
	border : 2px dashed #333;
	background-color : #ffe;
	padding: 2;
	width: 1000px;
}

div.spacer {clear: both;}
</style>
</head>
<body>
<?php include_once("menu.php"); ?>
	<h1>Top Videos</h1>
	<div class="items">
		<div class="spacer"></div>
<?php
$i = 0;
foreach($items as $item)
{
	echo "
	<div class=\"item\">
		<p>
			<a href=\"./player.php?sig=$item->sig\" title=\"$item->title\">
				<img src=\"$item->thumbnail\" width=\"154\" height=\"114\" alt=\"$item->title\" title=\"$item->title\" />
			</a>
			<br />
			<a href=\"./player.php?sig=$item->sig\" title=\"$item->title\">$item->title
			</a>
		</p>
	</div>";
	$i = $i+1;
	if ($i == 9) break;
}
?>
		<div class="spacer"></div>
	</div>
</body></html>